﻿function getCookie(name) {
    var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
    if (arr = document.cookie.match(reg))
        return unescape(arr[2]);
    else
        return null;
}

function getLoginUrl() {
    var LoginUrl = getCookie("LoginUrl");
    if (!LoginUrl) {
        LoginUrl = "/Login/Index";
    }
    return LoginUrl;
}


function getWeek(str) {
    let day = Date.parse(str);
    //如果不是当年的第一天不是星期一，则该日所属周数为上一年的最后一周
    day = new Date(day);

    if (day.getDay() !== 1) {
        day = day.getTime() - 24 * 60 * 60 * 1000
        day = new Date(day);
    }
    day.setMonth(0);
    day.setDate(1);
    day.setHours(0);
    day.setMinutes(0);
    day.setSeconds(0);//到这里就得到该年的一月一日

    let today = Date.parse(str);
    today = new Date(today);
    let todayWeek = today.getDay()

    //计算日期是一年中的第几天
    let rankDay = Math.ceil((today.getTime() - day.getTime()) / (1000 * 24 * 60 * 60))
    let rankWeek = Math.ceil(rankDay / 7)
    rankWeek = rankWeek < 10 ? ("0" + rankWeek) : rankWeek
    let year = day.getFullYear().toString()
    return year + "年第" + rankWeek + "周";
}